<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Statement extends Model
{
    use SoftDeletes;

    protected $dates = ['deleted_at'];

    protected $fillable = [
        'group_user_id', 'copper',
        'explanation', 'model_id', 'model_type',
    ];

    protected $hidden = [
        'group_user_id', 'model_id', 'model_type',
        'created_at', 'updated_at',
    ];

    /**
     * @param $value
     * @return string|array
     */
    public function getExplanationAttribute($value)
    {
        switch ($this->model_type) {
            case 'quiz':
                $value = json_decode($value, true);
                break;
        }
        return $value;
    }
}
